const DEV_URL = 'http://192.168.2.43'
const TEST_URL = 'http://test.8ykj.cn'
const PLA_URL = 'http://admint.smctc.cn'
const YD_URL = 'http://ydt.smctc.cn'
const HY_URL = 'http://hyt.smctc.cn'
const PRO_PLA_URL = 'http://dcm.smctc.cn.cn'
const PRO_YD_URL = 'http://yd.smctc.cn'
const PRO_HY_URL = 'http://hy.smctc.cn'
const SYMJ_URL = 'http://symj.smctc.cn'
const YHRD_URL = 'http://yhrd.smctc.cn'
const HYJH_URL = 'http://hyjh.smctc.cn'
const HYMH_URL = 'http://hymh.smctc.cn'
const ZCMKY_URL = 'http://zcm.smctc.cn'
const HNHG_URL = 'http://hnhg.smctc.cn'
const GLG_URL = 'http://glgny.smctc.cn'
const SSP_URL = 'http://ylssp.smctc.cn'

const getDomain = () => {
  return location.origin
}

export const getEnvType = () => {
  if ([DEV_URL].includes(getDomain())) {
    return 'DEV'
  }
  if ([TEST_URL].includes(getDomain())) {
    return 'TEST'
  }
  if (
    [PLA_URL, YD_URL, PRO_PLA_URL, PRO_YD_URL].includes(
      getDomain()
    )
  ) {
    return 'YIDONG'
  }
  if (
    [
      HY_URL,
      SYMJ_URL,
      PRO_HY_URL,
      HYJH_URL,
      HYMH_URL
    ].includes(getDomain())
  ) {
    return 'HENGYUAN'
  }
  if ([ZCMKY_URL].includes(getDomain())) {
    return 'ZHAOCANGMAO'
  }
  if ([YHRD_URL].includes(getDomain())) {
    return 'RDGS'
  }
  if ([HNHG_URL].includes(getDomain())) {
    return 'HNHG'
  }
  if ([GLG_URL].includes(getDomain())) {
    return 'GLG'
  }
  if ([SSP_URL].includes(getDomain())) {
    return 'SSP'
  }
  return ''
}

export const getAssetsUrl = (url) => {
  return new URL(url, import.meta.url).href
}

export const getTitle = () => {
  if ([DEV_URL].includes(getDomain())) {
    return '神煤交易'
  }
  if ([TEST_URL].includes(getDomain())) {
    return '神煤交易'
  }
  if (
    [PLA_URL, YD_URL, PRO_PLA_URL, PRO_YD_URL].includes(
      getDomain()
    )
  ) {
    return '陕西益东矿业'
  }
  if ([SYMJ_URL].includes(getDomain())) {
    return '三一煤井'
  }
  if ([YHRD_URL].includes(getDomain())) {
    return '热电公司'
  }
  if ([HY_URL, PRO_HY_URL].includes(getDomain())) {
    return '恒源集团'
  }
  if ([HYJH_URL].includes(getDomain())) {
    return '陕西恒源焦化'
  }
  if ([HYMH_URL].includes(getDomain())) {
    return '陕西恒源煤化'
  }
  if ([ZCMKY_URL].includes(getDomain())) {
    return '赵仓峁矿业'
  }
  if ([HNHG_URL].includes(getDomain())) {
    return '汇能化工'
  }
  if ([GLG_URL].includes(getDomain())) {
    return '圪柳沟矿业'
  }
  if ([SSP_URL].includes(getDomain())) {
    return '神树畔矿业'
  }
  return ''
}

export const getTabInfo = () => {
  const icon: any = document.querySelector(
    "link[rel*='icon']"
  )
  const loadingTitle: any = document.querySelector(
    '.app-loading-title#loadingTile'
  )
  icon['href'] = getTabIconUrl()
  document.title = getTitle()
  loadingTitle.innerHTML = getTitle()
}

const getTabIconUrl = () => {
  if (['YIDONG'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-yd.ico',
      import.meta.url
    ).href
  }
  if (['HENGYUAN'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-hy.ico',
      import.meta.url
    ).href
  }
  if (['ZHAOCANGMAO'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-zcm.ico',
      import.meta.url
    ).href
  }
  if (['DEV', 'TEST', 'HNHG'].includes(getEnvType())) {
    return new URL('../public/favicon.ico', import.meta.url)
      .href
  }
  if (['RDGS'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-rd.ico',
      import.meta.url
    ).href
  }
  if (['GLG'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-glg.ico',
      import.meta.url
    ).href
  }
  if (['SSP'].includes(getEnvType())) {
    return new URL(
      '../public/favicon-ssp.ico',
      import.meta.url
    ).href
  }
  return ''
}
